﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ControlYSeguimiento.Domain;
using ControlYSeguimiento.Logging;

namespace ControlYSeguimiento_Web_App
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Logger.Instance.Info(this,"Logueando usuario " + TextBoxUser.Text.Trim() + "...");

                #if DEBUG == false
                Customer customer = Facade.Instance.ValidateCustomerByNameAndPassword(TextBoxUser.Text.Trim() , TextBoxPassword.Text.Trim());                 
#else
                Customer customer = new Customer
                {
                    UserName = "lolo",
                    Surname = "Surname",
                    Password = "123456",
                    Name = "Name",
                    MapZoom = 10,
                    MapCoordinate = new Coordinate("-34.48894618571428", "-58.49734540000001"),
                    Mail = "mail",
                    Id = 1,
                    RefreshMapTimer = "30000",
                    EnableAtFirstUse = false,
                    Enable = true,
                    CustomerPlatform = new Platform {Id=1 }

                };
                #endif

                if (customer != null)
                {
                    HttpCookie cookie = new HttpCookie("customerLogged");
              
                    cookie.Values.Add("customerUserName", customer.UserName);
                    cookie.Expires = DateTime.Now.AddHours(3);
                    Response.Cookies.Add(cookie);
                    Response.Redirect("~/Monitoring/Monitoring.aspx");
                    lblBigMessage.Text = String.Empty;
                    lblBigMessage.Visible = false;
                }
                else
                {
                    lblBigMessage.Text = "No existe el usuario o la contraseña es incorrecta";
                    lblBigMessage.Visible = true;
                }
            }
        }

        protected void btnNuevoUsuario_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                HttpCookie cookie = new HttpCookie("prospectToMail");
                cookie.Values.Add("prospectUserName", TextBoxNoUserName.Text);
                cookie.Values.Add("prospectMail", TextBoxNoUserMail.Text);
                cookie.Expires = DateTime.Now.AddMinutes(2);
                Response.Cookies.Add(cookie);
                Response.Redirect("~/Mailing/Mailing.aspx");
            }
        }     
    }
}
